// pages/passenger/passenger.js
var util_md5 = require('../../utils/md5.js');
var util_sha1 = require('../../utils/sha1.js');
var API_Key = "chaotingjianshen0012";
var App = getApp();
function jsonSort(jsonObj) {
    let arr = [];
    for (var key in jsonObj) {
        arr.push(key)
    }
    arr.sort();
    let str = '';
    for (var i in arr) {
        str += arr[i] + "=" + jsonObj[arr[i]] + "&"
    }
    return str.substr(0, str.length - 1)
} 
function coding(data) {
    var detail = util_sha1.sha1(jsonSort(data))
    var datas_detail = util_md5.hexMD5(detail)
    var str = datas_detail;
    str = str.toUpperCase();
    return str;
}
Page({

    /**
     * 页面的初始数据
     */
    data: {
        member_list_box: [],
        membership_list_box: [],
        type: 0, //会籍列表状态
        wxSearchData: '', //搜索
        height: 0,
        index: 0,
        currentTab: 0, //tab切换值
        chicknum: 1, //私有公有切换
        flag_screen: true, //筛选
        user_status_vip: [{
            id: 1,
            name: '今日入场',
            checked: false
        }, {
            id: 2,
            name: '本周入场',
            checked: false
        }, {
            id: 3,
            name: '本月入场',
            checked: false
        }, {
            id: 4,
            name: '今日上课',
            checked: false
        }, {
            id: 5,
            name: '本周上课',
            checked: false
        }, {
            id: 6,
            name: '本月上课',
            checked: false
        }, {
            id: 7,
            name: '本周维护',
            checked: false
        }, {
            id: 8,
            name: '今日新增',
            checked: false
        }, {
            id: 9,
            name: '本周新增',
            checked: false
        }], //客户状态（私教）
        user_status_caller: [{
            id: 1,
            name: '今日入场',
            checked: false
        }, {
            id: 2,
            name: '本周入场',
            checked: false
        }, {
            id: 3,
            name: '今日维护',
            checked: false
        }, {
            id: 4,
            name: '本周维护',
            checked: false
        }, {
            id: 5,
            name: '今日新增',
            checked: false
        }, {
            id: 6,
            name: '本周新增',
            checked: false
        }], //
        users_status_vip: [], //客户状态(会员)
        users_status_caller: [], //客户状态（潜客）
        users_tags: [{
            id: 1,
            name: '消费力强',
            checked: false
        }, {
            id: 2,
            name: '消费力弱',
            checked: false
        }, {
            id: 3,
            name: '离家远',
            checked: false
        }, {
            id: 4,
            name: '距离近',
            checked: false
        }, {
            id: 5,
            name: '友善型',
            checked: false
        }, {
            id: 6,
            name: '刻薄型',
            checked: false
        }],
        user_tags: [],
        // rank: '', //客户级别
        workout_habit: '', //有无
        source_type: [],
        sources_type: [{
            id: 1,
            name: '新展',
            checked: false
        }, {
            id: 2,
            name: '轮排',
            checked: false
        }, {
            id: 3,
            name: '转介绍',
            checked: false
        }, {
            id: 4,
            name: '大众点评',
            checked: false
        }, {
            id: 5,
            name: '今日头条',
            checked: false
        }, {
            id: 6,
            name: '公众号',
            checked: false
        }, {
            id: 7,
            name: '电话咨询',
            checked: false
        }, {
            id: 8,
            name: '广告',
            checked: false
        }, {
            id: 9,
            name: '微信',
            checked: false
        }, {
            id: 10,
            name: '公开课',
            checked: false
        }, {
            id: 11,
            name: '开放日',
            checked: false
        }, {
            id: 12,
            name: '体验卡',
            checked: false
        }, {
            id: 13,
            name: '美团',
            checked: false
        }],
        level: '',
        membership_list: [],
        membership_id: [],
        privata_sort_list: ['综合排序', '消耗课时最多', '消耗课时最少', '剩余课时最多', '剩余课时最少', '购买课时最多', '购买课时最少', '上次上课最近', '上次上课最远'],//私教的排序
        sort_list: ['综合排序', '办卡最早', '办卡最晚', '跟进时间最早', '跟进时间最晚'],
        orderBy: 1,
        box_list: [],
        counts: '', //共多少人
        return_counts: '', //找到多少人
        page:1,
        limit:10,
        distribution_count: '',//已分配
        distribution_no_count:'',//未分配
        box_one:[],
        box_two:[],
        hasOnShow:false,
        show_text: false,
    },
    /**
     * 生命周期函数--监听页面显示
     */
    
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        var This = this;
        wx.getSystemInfo({
            success: function(res) {
                console.log((res.windowHeight - 50) * 2)
                This.setData({
                    height: res.windowHeight - 50,
                    level: wx.getStorageSync('level')
                    // level: 3
                })
            }
        })
        This.setData({
            box_one: [],
            box_two: [],
            box_list:[]
        })
        console.log(This.data.level)
        This.level_list();
        This.member_lists();
        if (This.data.currentTab == 0) {
            This.loading_caller();
        } else if (This.data.currentTab == 1) {
            This.loading_vip();
        }
        console.log(This.data.membership_list)
    },
    onShow: function () {
        var This = this;
        // if (This.data.hasOnShow == false) {
        //     return
        // }
        // This.setData({
        //     hasOnShow: true
        // })
        This.setData({
            member_list_box: [],
            membership_list_box: [],
            type: 0, //会籍列表状态
            wxSearchData: '', //搜索
            height: 0,
            index: 0,
            currentTab: 0, //tab切换值
            chicknum: 1, //私有公有切换
            flag_screen: true, //筛选
            user_status_vip: [{
                id: 1,
                name: '今日入场',
                checked: false
            }, {
                id: 2,
                name: '本周入场',
                checked: false
            }, {
                id: 3,
                name: '本月入场',
                checked: false
            }, {
                id: 4,
                name: '今日上课',
                checked: false
            }, {
                id: 5,
                name: '本周上课',
                checked: false
            }, {
                id: 6,
                name: '本月上课',
                checked: false
            }, {
                id: 7,
                name: '本周维护',
                checked: false
            }, {
                id: 8,
                name: '今日新增',
                checked: false
            }, {
                id: 9,
                name: '本周新增',
                checked: false
            }], //客户状态（私教）
            user_status_caller: [{
                id: 1,
                name: '今日入场',
                checked: false
            }, {
                id: 2,
                name: '本周入场',
                checked: false
            }, {
                id: 3,
                name: '今日维护',
                checked: false
            }, {
                id: 4,
                name: '本周维护',
                checked: false
            }, {
                id: 5,
                name: '今日新增',
                checked: false
            }, {
                id: 6,
                name: '本周新增',
                checked: false
            }], //客户状态（普通）
            users_status_vip: [], //客户状态(会员)
            users_status_caller: [], //客户状态（潜客）
            users_tags: [{
                id: 1,
                name: '消费力强',
                checked: false
            }, {
                id: 2,
                name: '消费力弱',
                checked: false
            }, {
                id: 3,
                name: '离家远',
                checked: false
            }, {
                id: 4,
                name: '距离近',
                checked: false
            }, {
                id: 5,
                name: '友善型',
                checked: false
            }, {
                id: 6,
                name: '刻薄型',
                checked: false
            }],
            user_tags: [],
            // rank: '', //客户级别
            workout_habit: '', //有无
            source_type: [],
            sources_type: [{
                id: 1,
                name: '新展',
                checked: false
            }, {
                id: 2,
                name: '轮排',
                checked: false
            }, {
                id: 3,
                name: '转介绍',
                checked: false
            }, {
                id: 4,
                name: '大众点评',
                checked: false
            }, {
                id: 5,
                name: '今日头条',
                checked: false
            }, {
                id: 6,
                name: '公众号',
                checked: false
            }, {
                id: 7,
                name: '电话咨询',
                checked: false
            }, {
                id: 8,
                name: '广告',
                checked: false
            }, {
                id: 9,
                name: '微信',
                checked: false
            }, {
                id: 10,
                name: '公开课',
                checked: false
            }, {
                id: 11,
                name: '开放日',
                checked: false
            }, {
                id: 12,
                name: '体验卡',
                checked: false
            }, {
                id: 13,
                name: '美团',
                checked: false
            }],
            level: '',
            membership_list: [],
            membership_id: [],
            privata_sort_list: ['综合排序', '消耗课时最多', '消耗课时最少', '剩余课时最多', '剩余课时最少', '购买课时最多', '购买课时最少', '上次上课最近', '上次上课最远'],//私教的排序
            sort_list: ['综合排序', '办卡最早', '办卡最晚', '跟进时间最早', '跟进时间最晚'],
            orderBy: 1,
            box_list: [],
            box_one: [],
            box_two: [],
            counts: '', //共多少人
            return_counts: '',//找到多少人
            page:1,
        })
        This.onLoad();
    },
    // 私教会员  
    loading_vip() {
        var This = this;
        // This.setData({
        //     box_list: []
        // })
        // var pack = {
        //     openid: wx.getStorageSync('openid'),
        //     phone: wx.getStorageSync('phone'),
        //     store_id: wx.getStorageSync('store_id'),
        //     status: This.data.chicknum,
        //     // status:2,
        //     Keyword: This.data.wxSearchData,
        //     order: This.data.orderBy,
        //     customer_status: This.data.users_status_vip,
        //     // rank: This.data.rank,
        //     workout_habit: This.data.workout_habit,
        //     client_tag: This.data.user_tags,
        //     source_type: This.data.source_type,
        //     ascription_coach_id: This.data.membership_id,
        // }
        // var api = coding(pack);
        if (This.data.users_status_vip.length > 0) {
            var a = This.data.users_status_vip.join(',')
        } else {
            var a = '';
        }
        // if (This.data.workout_habit.length > 0) {
        //     var b = This.data.workout_habit.join(',')
        // } else {
        //     var b = '';
        // }
        if (This.data.user_tags.length > 0) {
            var c = This.data.user_tags.join(',')
        } else {
            var c = '';
        }
        if (This.data.source_type.length > 0) {
            var d = This.data.source_type.join(',')
        } else {
            var d = '';
        }
        if (This.data.membership_id.length > 0) {
            var e = This.data.membership_id.join(',')
        } else {
            var e = '';
        }
        This.setData({
            show_text: false
        })
        App._get("coach/Maintain/get_ordinary_private_member_list", {
            // signature: api,
            openid: wx.getStorageSync('openid'),
            phone: wx.getStorageSync('phone'),
            store_id: wx.getStorageSync('store_id'),
            // distribution_status: This.data.chicknum,
            // status:2,
            keyword: This.data.wxSearchData,
            order: This.data.orderBy,
            customer_status: a,
            workout_habit: This.data.workout_habit,
            client_tag: c,
            source_type: d,
            ascription_coach_id: e,
            page: This.data.page,
            limit: This.data.limit,
        }, function(res) {
            if (res.status == 1) {
                if (res.data.length>0){
                    for (var index in res.data) {
                        This.data.box_two.push(res.data[index]);
                    }
                    This.setData({
                        box_list: This.data.box_two,
                        counts: res.total_num, //共多少人
                        return_counts: res.find_num //找到多少人
                    })
                    if (This.data.box_two.length == 0 && This.data.box_list.length == 0){
                        This.setData({
                            show_text:false
                        })
                    }
                }else{
                    // wx.showToast({
                    //     title: '加载到底部',
                    //     icon: 'none',
                    //     duration: 500
                    // })
                    This.setData({
                        box_list: This.data.box_two,
                        counts: res.total_num, //共多少人
                        return_counts: res.find_num, //找到多少人
                    })
                    if (This.data.page != 1) {
                        This.setData({
                            show_text: true
                        })
                    }
                } 
            } else {
                wx.showToast({
                    title: res.error.error,
                    image: '../../image/icon_danger.png',
                    duration: 2000
                })
            }
        })
    },
    // 普通会员
    loading_caller() {
        var This = this;
        // var pack = {
        //     openid: wx.getStorageSync('openid'),
        //     phone: wx.getStorageSync('phone'),
        //     store_id: wx.getStorageSync('store_id'),
        //     distribution_status: This.data.chicknum,
        //     Keyword: This.data.wxSearchData,
        //     order: This.data.orderBy,
        //     customer_status: This.data.users_status_caller,
        //     workout_habit: This.data.workout_habit,
        //     client_tag: This.data.user_tags,
        //     source_type: This.data.source_type,
        //     ascription_coach_id: This.data.membership_id,
        // }
        // var api = coding(pack);
        if (This.data.users_status_caller.length>0){
            var a = This.data.users_status_caller.join(',')
        }else {
            var a = '';
        }
        // if (This.data.workout_habit.length > 0) {
        //     console.log(This.data.workout_habit)
        //     var b = This.data.workout_habit.join(',')
        // } else {
        //     var b = '';
        // }
        if (This.data.user_tags.length > 0) {
            var c = This.data.user_tags.join(',')
        } else {
            var c = '';
        }
        if (This.data.source_type.length > 0) {
            var d = This.data.source_type.join(',')
        } else {
            var d = '';
        }
        if (This.data.membership_id.length > 0) {
            var e = This.data.membership_id.join(',')
        } else {
            var e = '';
        }
        This.setData({
            show_text: false
        })
        App._get('coach/Maintain/get_ordinary_member_list', {
            // signature: api,
            openid: wx.getStorageSync('openid'),
            phone: wx.getStorageSync('phone'),
            store_id: wx.getStorageSync('store_id'),
            keyword: This.data.wxSearchData,
            order: This.data.orderBy,
            distribution_status: This.data.chicknum,
            customer_status: a,
            workout_habit: This.data.workout_habit,
            client_tag: c,
            source_type: d,
            ascription_coach_id: e,
            page:This.data.page, 
            limit:This.data.limit,
        }, function(res) {
            if (res.status == 1) {
                console.log(res.status)
                if (res.data.length > 0) {
                    if (This.data.page == 1) {
                        This.setData({
                            box_one: [],
                            box_list:[]
                        })
                    }
                    for (var index in res.data) {
                        This.data.box_one.push(res.data[index]);
                    }
                    This.setData({
                        box_list: This.data.box_one,
                        counts: res.total_num, //共多少人
                        return_counts: res.find_num,//找到多少人
                        distribution_count: res.distribution_count,//已分配
                        distribution_no_count: res.distribution_no_count,//未分配
                    })
                    if (This.data.box_one.length == 0 && This.data.box_list.length == 0) {
                        This.setData({
                            show_text: false
                        })
                    }
                } else {
                    // wx.showToast({
                    //     title: '加载到底部',
                    //     icon:'none',
                    //     duration:500
                    // })
                    This.setData({
                        box_list: This.data.box_one,
                        counts: res.total_num, //共多少人
                        return_counts: res.find_num,//找到多少人
                        distribution_count: res.distribution_count,//已分配
                        distribution_no_count: res.distribution_no_count,//未分配
                    })
                    if(This.data.page != 1){
                        This.setData({
                            show_text: true
                        })
                    }
                }
            } else {
                console.log(res.status)
                wx.showToast({
                    title: res.error.error,
                    image: '../../image/icon_danger.png',
                    duration: 2000
                })
            }
        })
    },
    //归属会籍详情
    level_list() {
        var This = this;
        // var data = {
        //     store_id: wx.getStorageSync('store_id'),
        //     openid: wx.getStorageSync('openid'),
        //     phone: wx.getStorageSync('phone'),
        //     token: API_Key,
        //     type: 0
        // }
        // var str = coding(data);
        App._get('/coach/member/get_coach_list', {
            // signature: str,
            store_id: wx.getStorageSync('store_id'),
            openid: wx.getStorageSync('openid'),
            phone: wx.getStorageSync('phone'),
            // store_id: 53,
            // openid: 1,
            // phone: 15612340001,
        }, function(res) {
            if (res.status == 1) {
                var list = [];
                var checked = [];
                for (var i = 0; i < res.coach_list.length; i++) {
                    res.coach_list[i].checked = false
                    list.push(res.coach_list[i])
                    checked.push(res.coach_list[i].coach_name)
                }
                console.log(list)
                This.setData({
                    membership_list: list,
                    membership_list_box: checked
                })
            } else {
                wx.showToast({
                    title: res.error,
                    image: '../../image/icon_danger.png',
                    duration: 2000
                })
            }
        })
    },
    clickTab(e) {
        console.log(e)
        var This = this;
        if (This.data.currentTab === e.target.dataset.current) {
            return false;
        } else {
            This.setData({
                currentTab: e.target.dataset.current,
                chicknum:1,
                page:1,
                orderBy: 1,
                index: 0,
                users_status_vip: [],
                users_status_caller: [],
                is_coach: '',
                user_tags: [],
                workout_habit: '',
                is_coach: '',
                source_type: [],
                membership_id: [],
                wxSearchData:'',
                show_text: false
            })
            if (This.data.currentTab == 0) {
                This.setData({
                    box_one: [],
                })
                This.loading_caller();
            } else if (This.data.currentTab == 1) {
                This.setData({
                    box_two: [],
                })
                This.loading_vip();
            }
        }
    },
    clickTabs(e) {
        console.log(e)
        var This = this;
        if (This.data.chicknum === e.target.dataset.chicktab) {
            return false;
        } else {
            This.setData({
                box_list: [],
                box_one: [],
                page:1,
                chicknum: e.target.dataset.chicktab,
                orderBy: 1,
                index: 0,
                users_status_vip: [],
                users_status_caller: [],
                is_coach: '',
                user_tags: [],
                workout_habit: '',
                is_coach: '',
                source_type: [],
                membership_id: [],
                wxSearchData:'',
                show_text: false
            })
        }
        This.loading_caller();
        console.log(This.data.privata_sort_list)
    },
    //搜索
    wxSearchInput(e) {
        var This = this;
        This.setData({
            wxSearchData: e.detail.value,
            page:1,
        })
        if(e.detail.value == ''){
            wxSearchData:0
        }
        console.log(This.data.wxSearchData)
        if (This.data.currentTab == 0) {
            This.setData({
                box_list: [],
                box_one: [],
            })
            This.loading_caller();
        } else if (This.data.currentTab == 1) {
            This.setData({
                box_list: [],
                box_two: [],
            })
            This.loading_vip();
        }
    },
    //综合排序
    sort_change(e) {
        var This = this;
        var orderBy = parseInt(e.detail.value)
        This.setData({
            orderBy: orderBy,
            index: e.detail.value,
            page:1
        })
        console.log(This.data.orderBy)
        if (This.data.currentTab == 0) {
            This.setData({
                box_list: [], 
                box_one: []  
            })
            This.loading_caller();
        } else if (This.data.currentTab == 1) {
            This.setData({
                box_list: [],
                box_two: []
            })
            This.loading_vip();
        }
    },
    //筛选弹窗
    preventTouchMove: function(e) {},
    show_screen() {
        var This = this;
        for (var y = 0; y < This.data.membership_list.length; y++) {
            This.data.membership_list[y].checked = false;
            This.setData({
                membership_list: This.data.membership_list
            })
        }
        This.setData({
            flag_screen: false,
            page:1
        })
    },
    hide_screen() {
        var This = this;
        This.setData({
            flag_screen: true,
        })
        console.log(This.data.box_list)
        if (This.data.currentTab == 0) {
            This.setData({
                box_list: [],
                box_one: []
            })
            This.loading_caller();
        } else if (This.data.currentTab == 1) {
            This.setData({
                box_list: [],
                box_two: []
            })
            This.loading_vip();
        }

    },
    hide_screen1() {
        var This = this;
        for (var i = 0; i < This.data.user_status_vip.length; i++) {
            This.data.user_status_vip[i].checked = false;
            This.setData({
                user_status_vip: This.data.user_status_vip,
            })
        }
        for (var i = 0; i < This.data.user_status_caller.length; i++) {
            This.data.user_status_caller[i].checked = false;
            This.setData({
                user_status_caller: This.data.user_status_caller,
            })
        }
        for (var j = 0; j < This.data.users_tags.length; j++) {
            This.data.users_tags[j].checked = false;
            This.setData({
                users_tags: This.data.users_tags,
            })
        }
        for (var x = 0; x < This.data.sources_type.length; x++) {
            This.data.sources_type[x].checked = false;
            This.setData({
                sources_type: This.data.sources_type,
            })
        }
        for (var y = 0; y < This.data.membership_list.length; y++) {
            This.data.membership_list[y].checked = false;
            This.setData({
                membership_list: This.data.membership_list
            })
        }
        This.setData({
            users_status_vip: [],
            users_status_caller: [],
            is_coach: '',
            user_tags: [],
            workout_habit: '',
            is_coach: '',
            source_type: [],
            membership_id: [],
            flag_screen: true,
        })
    },
    reset_screen() {
        var This = this;
        for (var i = 0; i < This.data.user_status_vip.length; i++) {
            This.data.user_status_vip[i].checked = false;
            This.setData({
                user_status_vip: This.data.user_status_vip,
            })
        }
        for (var i = 0; i < This.data.user_status_caller.length; i++) {
            This.data.user_status_caller[i].checked = false;
            This.setData({
                user_status_caller: This.data.user_status_caller,
            })
        }
        for (var j = 0; j < This.data.users_tags.length; j++) {
            This.data.users_tags[j].checked = false;
            This.setData({
                users_tags: This.data.users_tags,
            })
        }
        for (var x = 0; x < This.data.sources_type.length; x++) {
            This.data.sources_type[x].checked = false;
            This.setData({
                sources_type: This.data.sources_type,
            })
        }
        for (var y = 0; y < This.data.membership_list.length; y++) {
            This.data.membership_list[y].checked = false;
            This.setData({
                membership_list: This.data.membership_list
            })
        }
        console.log(This.data.membership_list)
        This.setData({
            users_status_vip: [],
            users_status_caller: [],
            is_coach: '',
            user_tags: [],
            workout_habit: '',
            is_coach: '',
            source_type: [],
            membership_id: [],
            // membership_list:[],
        })
    },
    // 私教；列表的获取
    member_lists() {
        var This = this;
        // var data = {
        //     store_id: wx.getStorageSync('store_id'),
        //     openid: wx.getStorageSync('openid'),
        //     phone: wx.getStorageSync('phone'),
        //     type: 1,
        //     token: API_Key,
        // }
        // var str = coding(data);
        App._get('coach/member/get_coach_list', {
            // signature: str,
            store_id: wx.getStorageSync('store_id'),
            openid: wx.getStorageSync('openid'),
            phone: wx.getStorageSync('phone'),
            // store_id: 53,
            // openid:1,
            // phone: 15612340001,
        }, function(res) {
            if (res.status == 1) {
                var list = [];
                var checked_box = []
                for (var i = 0; i < res.coach_list.length; i++) {
                    res.coach_list[i].checked = false
                    list.push(res.coach_list[i])
                }
                for (var i = 0; i < res.coach_list.length; i++) {
                    if (res.coach_list[i].coach_name == '全部私教'){

                    }else{
                        checked_box.push(res.coach_list[i].coach_name)
                    }
                }
                console.log(list)
                This.setData({
                    member_list: list,
                    member_list_box: checked_box
                })
                console.log(This.data.member_list_box)
            } else {
                wx.showToast({
                    title: res.error,
                    image: '../../image/icon_danger.png',
                    duration: 2000
                })
            }
        })
    },
    // 更改教练的功能
    change_coach:function(e){
        var This = this;
        console.log(e)
        wx.navigateTo({
            url: '../transferLessons/transferLessons?member_id=' + e.currentTarget.id
        })
    },
    // 私教的分配
    bindChanges_member_higer:function(e){
        var This = this;
        var index = parseInt(e.detail.value)+1
        var id = This.data.member_list[index].id
        This.setData({
            member_id: id
        })
        if (This.data.currentTab == 0) {
            App._get('coach/Maintain/member_distribution', {
                store_id: wx.getStorageSync('store_id'),
                openid: wx.getStorageSync('openid'),
                phone: wx.getStorageSync('phone'),
                member_id: e.currentTarget.id,//会员id
                distribution_coach_id: This.data.member_id,//私教ID
            }, function (res) {
                if (res.status == 1) {
                    setTimeout(function () {
                        wx.showToast({
                            title: '分配成功',
                            icon: 'none',
                            duration: 2000
                        })
                    }, 0)

                    setTimeout(function () {
                        This.loading_caller();
                    }, 0)
                } else {
                    wx.showToast({
                        title: res.error,
                        image: '../../image/icon_danger.png',
                        duration: 2000
                    })
                }
            })
        } else if (This.data.currentTab == 1) {
            App._get('coach/Maintain/member_distribution', {
                store_id: wx.getStorageSync('store_id'),
                openid: wx.getStorageSync('openid'),
                phone: wx.getStorageSync('phone'),
                member_id: e.currentTarget.id,//会员id
                distribution_coach_id: This.data.member_id,//私教ID
            }, function (res) {
                if (res.status == 1) {
                    setTimeout(function () {
                        wx.showToast({
                            title: '分配成功',
                            icon: 'none',
                            duration: 2000
                        })
                    }, 2000)

                    setTimeout(function () {
                        This.loading_vip();
                    }, 2000)

                } else {
                    wx.showToast({
                        title: res.desc,
                        image: '../../image/icon_danger.png',
                        duration: 2000
                    })
                }
            })
        }
    },
    // 普通的转出
    bindChanges_member(e) {
        console.log(e)
        var This = this;
        App._get('coach/Maintain/member_shift', {
            store_id: wx.getStorageSync('store_id'),
            openid: wx.getStorageSync('openid'),
            phone: wx.getStorageSync('phone'),
            member_id: e.currentTarget.id,//会员id
        }, function (res) {
            if (res.status == 1) {
                setTimeout(function () {
                    wx.showToast({
                        title: res.message,
                        icon: 'none',
                        duration: 2000
                    })
                }, 1000)

                setTimeout(function () {
                    This.loading_caller();
                }, 2000)
            } else {
                wx.showToast({
                    title: res.error,
                    image: '../../image/icon_danger.png',
                    duration: 2000
                })
            }
        })
    },
    //客户状态 （会员）
    user_status_vip(e) {
        var This = this;
        var user_status_vip = []
        var index = e.currentTarget.dataset.index;
        var item = This.data.user_status_vip[index];
        item.checked = !item.checked;
        This.setData({
            user_status_vip: This.data.user_status_vip,
        });
        for (var i = 0; i < This.data.user_status_vip.length; i++) {
            if (This.data.user_status_vip[i].checked) {
                user_status_vip.push(This.data.user_status_vip[i].id)
            }
        }
        This.setData({
            users_status_vip: user_status_vip
        })
        console.log(This.data.users_status_vip)
    },
    //客户状态 （潜客）
    user_status_caller(e) {
        var This = this;
        var user_status_caller = []
        var index = e.currentTarget.dataset.index;
        var item = This.data.user_status_caller[index];
        item.checked = !item.checked;
        This.setData({
            user_status_caller: This.data.user_status_caller,
        });
        for (var i = 0; i < This.data.user_status_caller.length; i++) {
            if (This.data.user_status_caller[i].checked) {
                user_status_caller.push(This.data.user_status_caller[i].id)
            }
        }
        This.setData({
            users_status_caller: user_status_caller
        })
        console.log(This.data.users_status_caller)
    },
 
    //有无私教课程
    is_coach(e) {
        var This = this;
        This.setData({
            is_coach: e.currentTarget.id
        })
        console.log(This.data.is_coach)
    },
    //客户标签
    user_tags(e) {
        var This = this;
        var users_tags = []
        var index = e.currentTarget.dataset.index;
        var item = This.data.users_tags[index];
        item.checked = !item.checked;
        This.setData({
            users_tags: This.data.users_tags,
        });
        for (var i = 0; i < This.data.users_tags.length; i++) {
            if (This.data.users_tags[i].checked) {
                users_tags.push(This.data.users_tags[i].id)
            }
        }
        This.setData({
            user_tags: users_tags
        })
        console.log(This.data.user_tags)
    },
    //健康习惯
    workout_habit(e) {
        var This = this;
        This.setData({
            workout_habit: e.currentTarget.id
        })
        console.log(This.data.workout_habit)
    },
    //客户来源
    source_type(e) {
        var This = this;
        var source_type = []
        var index = e.currentTarget.dataset.index;
        var item = This.data.sources_type[index];
        item.checked = !item.checked;
        This.setData({
            sources_type: This.data.sources_type,
        });
        for (var i = 0; i < This.data.sources_type.length; i++) {
            if (This.data.sources_type[i].checked) {
                source_type.push(This.data.sources_type[i].id)
            }
        }
        This.setData({
            source_type: source_type
        })
        console.log(This.data.source_type)
    },
    membership_list(e) {
        var This = this;
        var membership_list = []
        var index = e.currentTarget.dataset.index;
        var item = This.data.membership_list[index];
        item.checked = !item.checked;
        This.setData({
            membership_list: This.data.membership_list,
        });
        for (var i = 0; i < This.data.membership_list.length; i++) {
            if (This.data.membership_list[i].checked) {
                membership_list.push(This.data.membership_list[i].id)
            }
        }
        This.setData({
            membership_id: membership_list
        })
        console.log(This.data.membership_id)
    },
    //打电话
    call_phone(e) {
        wx.makePhoneCall({
            phoneNumber: e.currentTarget.id,
        })
    },

    to_customer_information: function(e) {
        console.log(e)
        var This = this;
        if (This.data.currentTab == 0) {
            wx.navigateTo({
                url: '../latent_maintenance/latent_maintenance?id=' + e.currentTarget.dataset.id + '&type=' + 1,
            })
        } else {
            wx.navigateTo({
                url: '../latent_maintenance/latent_maintenance?id=' + e.currentTarget.dataset.id + '&type=' + 2,
            })
        }

    },
    //添加维护
    caller_details(e) {
        var This = this;
        if(This.data.currentTab == 0){
            wx.navigateTo({
                url: '/pages/add_the_maintenance/add_the_maintenance?type=1' + '&id=' + e.currentTarget.id,
            })
        }else {
            wx.navigateTo({
                url: '/pages/add_the_maintenance/add_the_maintenance?type=2' + '&id=' + e.currentTarget.id,
            })
        }
        
    },
    // vip_details(e) {
    //     wx.navigateTo({
    //         url: '/pages/add_the_maintenance/add_the_maintenance?type=2' + '&id=' + e.currentTarget.id,
    //     })
    // },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {
        var This = this;
        var pasges = This.data.page;
        pasges = pasges + 1;
        This.setData({
            page: pasges
        })
        setTimeout(function () {
            if (This.data.currentTab == 0){
                This.loading_caller();
            } else if (This.data.currentTab == 1){
                This.loading_vip();
            } 
        }, 1000)
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    }
})